﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tour.szhome.common;
using TOUR.SZHOME.Attributes;
using TOUR.SZHOME.BLL;
using TOUR.SZHOME.Entity;

namespace tour.szhome.manage.area.Controllers
{
    [SelfOnly]
    public class LandscapeController : Controller
    {
        //
        // GET: /Landscape/
        LandscapeBLL _landbll = new LandscapeBLL();

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 编辑 or 新增视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            ViewBag.ID = id;
            ViewBag.uploadAddress = System.Configuration.ConfigurationManager.AppSettings["UploadAddress"];//获取上传文件地址 
            ViewBag.Folder = "others/";   //获取当前子文件夹
            LandscapeEntity model = new LandscapeEntity();
            if (id > 0)
            {
                model = _landbll.GetLandscapeByID(id);
            }
            return View(model);
        }

        /// <summary>
        /// 获取景区列表 -- 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [ActionName("get_landscape_list")]
        public ActionResult GetLandscapeList(int page = 1, int size = 10)
        {
            PageSet pageSet = new PageSet()
            {
                PageIndex = page,
                PageSize = size,
            };
            var data = new
            {
                page = page,
                pageSize = size,
                list = _landbll.GetLandscapeList(pageSet),
                recordCount = pageSet.RecordCount,
                totalpage = pageSet.PageCount
            };
            return Json(data);
        }

        /// <summary>
        /// 动态编辑
        /// </summary>
        /// <returns></returns>
        [ActionName("json_edit")]
        public ActionResult Json_Edit(LandscapeEntity model)
        {
            return Json(_landbll.EditLandscape(model));
        }

        /// <summary>
        /// 根据ID删除对象
        /// </summary>
        /// <param name="nid"></param>
        /// <returns></returns>
        [ActionName("json_delete")]
        public ActionResult DelByID(int lid)
        {
            return Json(_landbll.DelByID(lid), JsonRequestBehavior.AllowGet);
        }
    }
}
